import Mock from 'mockjs'
import {param2Obj} from '@/utils'

const List = [],
  count = 100;


for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment(1, 100)',
    bind_time: '@datetime()',
    bank_code: Mock.mock('@float(0)'),
    account: Mock.mock('@float(0)'),
    cardNo: Mock.mock('@float(0)'),
    deposit: Mock.Random.ctitle(20),
    'bankName|1': _.map(consts.PAYEE_BANKS, 'value'),
    delTime: '@datetime()',
    addTime: +Mock.Random.date('T'),
    member_id: Mock.mock('@natural(1, 100)'),
    cardno: Mock.mock('@float(0)'),
    bank_deposit: Mock.Random.ctitle(20),
    // 'type|1': ['CN', 'US', 'JP', 'EU'],
    'accountType|1': _.map(consts.ACCOUNT_TYPE, 'value'),
    'status|1': _.map(consts.BANK_STATUS, 'value'),
  }))
}


export default {
  [api.BANK_LOGS]: config => {
    const {page = 1, limit = 20} = param2Obj(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      if (status && Number(item.status) !== Number(status)) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },

}
